# -*- coding: utf-8 -*-
# @Time : 2025/2/27 11:20
# @Author : debbyszhang
# @File : tuils.py
# @desc :
import datetime
import os
import subprocess
import sys


def getCurrentMintus():
    now = datetime.datetime.now()
    # 构建时间戳字符串
    timestamp_str = now.strftime('%Y%m%d%H%M%S')
    return str(timestamp_str)


def set_permanent_env_variable(name, value):
    if sys.platform.startswith("win"):
        # Windows 系统
        command = f'setx {name} "{value}"'
        subprocess.run(command, shell=True, check=True)
        print(f"环境变量 {name} 已设置为 {value}，重启后生效。")
    elif sys.platform.startswith("linux") or sys.platform.startswith("darwin"):
        # macOS 或 Linux 系统
        config_file = "~/.bashrc"  # 或 ~/.zshrc
        with open(os.path.expanduser(config_file), "a") as f:
            f.write(f'\nexport {name}="{value}"\n')
            os.system('source ~/.bashrc')
        print(f"环境变量 {name} 已添加到 {config_file}，重启终端后生效。")
    else:
        raise NotImplementedError(f"不支持的操作系统: {sys.platform}")
# if __name__ == '__main__':
#     getCurrentMintus()